//////////////////////////////////////////////////////////////////////////
//
// This file is a part of UKROP project.
// Copyright (c) Vladimir Gumenuk
//
// PROJECT:         Xort Custom Debug Engine
// FILE:            Context.cpp
// AUTHOR:          Vladimir Gumenuk
// DATE:            Dec-2012 -- Jan-2013
// MODIFICATIONS:
//
//////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Context.h"
#include "dllmain.h"

//////////////////////////////////////////////////////////////////////////
//
CDocumentPosition::CDocumentPosition()
{

}

CDocumentPosition::~CDocumentPosition()
{

}

HRESULT CDocumentPosition::FinalConstruct()
{
    return S_OK;
}

void CDocumentPosition::FinalRelease()
{

}

void CDocumentPosition::Initialize( LPCOLESTR lpszDocName, TEXT_POSITION& posBegin, TEXT_POSITION& posEnd )
{
    m_bsDocName = lpszDocName;
    m_posBegin  = posBegin;
    m_posEnd    = posEnd;
}

STDMETHODIMP CDocumentPosition::GetFileName( BSTR *pbstrFileName )
{
    if( !pbstrFileName )
        return E_INVALIDARG;
    *pbstrFileName = SysAllocString( m_bsDocName );
    return S_OK;
}

STDMETHODIMP CDocumentPosition::GetDocument( IDebugDocument2 **ppDoc )
{
    CComQIPtr<IXProgram> spProg( _AtlModule.getProgramNoAddRef() );
    return spProg->FindSourceFile( m_bsDocName, ppDoc );
}

STDMETHODIMP CDocumentPosition::IsPositionInDocument( IDebugDocument2 *pDoc )
{
    return E_NOTIMPL;
}

STDMETHODIMP CDocumentPosition::GetRange( TEXT_POSITION *pBegPosition, TEXT_POSITION *pEndPosition )
{
    if( pBegPosition )
    {
        pBegPosition->dwLine   = m_posBegin.dwLine;
        pBegPosition->dwColumn = m_posBegin.dwColumn;
    }

    if( pEndPosition )
    {
        pEndPosition->dwLine   = m_posEnd.dwLine;
        pEndPosition->dwColumn = m_posEnd.dwColumn;
    }

    return S_OK;
}

